package com.tedu.egweibo.common.resulf;

import lombok.Getter;
import lombok.Setter;

/**
 * 统一结果响应
 * 规范Controller向前端回复的格式
 * 格式是由一个JSON对象表达，对应三个属性
 */
@Getter
@Setter
public class JsonResult {
    private Integer status;
    private String msg;
    private Object data;

    public JsonResult(StatusCode status) {
        this.status = status.getStatusCode();
        this.msg = status.getMessage();
    }

    public JsonResult(StatusCode status, Object data) {
        this(status);//调用本类的JsonResult(StatusCode status)构造器操作
        this.data = data;
    }

    public static JsonResult success(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS , data);
    }

    public static JsonResult success(){
        // 调用带参数的success
        // return new JsonResult(StatusCode.OPERATION_SUCCESS , data);
        return success(null);
    }
}
